
import { createI18n } from 'vue-i18n';
import type { I18n } from 'vue-i18n';
import Cookies from 'js-cookie';
import elementEnLocale from 'element-plus/es/locale/lang/en';
import elementZhLocale from 'element-plus/es/locale/lang/zh-cn';
import enLocale from './en';
import zhLocale from './zh';

const messages = {
  en: {
    ...enLocale,
    ...elementEnLocale,
  },
  zh: {
    ...zhLocale,
    ...elementZhLocale,
  },
};

// 创建 i18n 实例
const i18n: I18n = createI18n({
  // 关闭 Vue 2 兼容模式
  legacy: false,
  // 全局注入 $t 函数
  globalInjection: true,
  locale: Cookies.get('language') || 'zh',
  // 备用语言
  fallbackLocale: 'en',
  messages,
});

export default i18n;
